using StackExchange.Redis;

namespace GEM.Infrastructure.Redis;

public interface IRedisService
{
    /// <summary>
    /// 字符串类型操作
    /// </summary>
    /// <param name="key">键</param>
    /// <param name="value">值</param>
    /// <param name="expiry">过期时间</param>
    /// <returns></returns>
    Task SetStringAsync(string key, string value, TimeSpan? expiry = null);
    Task<string?> GetStringAsync(string key);

    /// <summary>
    /// 键操作
    /// </summary>
    /// <param name="key">键</param>
    /// <param name="expiry">过期时间</param>
    /// <returns></returns> <summary>
    Task DeleteKeyAsync(string key);
    Task ExpireKeyAsync(string key, TimeSpan? expiry = null);

    /// <summary>
    /// 哈希类型操作
    /// </summary>
    /// <param name="key">哈希表主键</param>
    /// <param name="field">字段名</param>
    /// <param name="value">值</param>
    /// <returns></returns>
    Task HashSetAsync(string key, string field, string value);
    Task<string?> HashGetAsync(string key, string field);

    /// <summary>
    /// 查找所有Hash所有字段
    /// </summary>
    Task<HashEntry[]> HashGetAllAsync(string key);

    /// <summary>
    ///  泛型写入Hash对象
    /// </summary>
    Task HashSetObjectAsync<T>(string key, string field, T value);
    /// <summary>
    ///  泛型读取Hash对象
    /// </summary>
    Task<T?> HashGetObjectAsync<T>(string key, string field);
    /// <summary>
    ///  泛型读取Hash所有对象
    /// </summary>
    Task<List<T>> HashGetAllObjectsAsync<T>(string key);

}